<div class="card-box">
    <!-- Row start -->
    <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6">
            <div class="am-btn-toolbar">
                <div class="am-btn-group am-btn-group-xs">
                    <!--<a class="am-btn am-btn-default" href="/goods/add.html"><span class="am-icon-plus"></span> 新增</a>-->
                    <!--<a class="am-btn am-btn-default"><span class="am-icon-archive"></span> 审核</a>
                    <a class="am-btn am-btn-default"><span class="am-icon-trash-o"></span> 删除</a>-->
                </div>
            </div>
        </div>

        <div class="am-u-sm-12 am-u-md-3">
            <div class="am-input-group am-input-group-sm">
                <input type="text" id="wards" class="am-form-field">
                <span class="am-input-group-btn">
				            <button id="sereach-w" class="am-btn am-btn-default" type="button">搜索</button>
				          </span>
            </div>
        </div>
    </div>
    <!-- Row end -->

    <!-- Row start -->
    <div class="am-g">
        <div class="am-u-sm-12">
                <table class="am-table am-table-striped am-table-hover table-main">
                    <thead>
                        <tr>
                            <th class="table-title">选择</th>
                            <th class="table-id">ID</th>
                            <th class="table-title">编码</th>
                            <th class="table-title">名称</th>
                            <th class="table-title">单位</th>
                            <th class="table-title">价格</th>
                            <th class="table-title">规格</th>
                            <th class="table-title">型号</th>
                            <th class="table-title">分类</th>
                            <th class="table-title">状态</th>
                            <th class="table-title">销售状态</th>
                        </tr>
                    </thead>
                    <tbody>
                        {{range .List}}
                        <tr>
                            <td><a class="am-btn am-btn-default" data-id="{{.Id}}" data-name="{{.Name}}">选择</a></td>
                            <td>{{.Id}}</td>
                            <td>{{.Gcode}}</td>
                            <td>{{.Name}}</td>
                            <td>{{.Units}}</td>
                            <td>{{.Price}}</td>
                            <td>{{.Spec}}</td>
                            <td>{{.Gmodel}}</td>
                            <td>{{.Sname}}</td>
                            <td>{{.Status}}</td>
                            <td>{{.SaleStatus}}</td>
                        </tr>
                        {{end}}
                    </tbody>
                </table>
                <p id="page-list">
                 {{str2html .page}}
                </p>
                <hr />
                <p>注：<span style="color:red">请删除分类之前进行确认</span></p>
                <p id="chage-goods-list">
                </p>
                <p>
                    <span id="next-button-s" class="am-btn am-btn-primary">下一步</span>
                </p>
        </div>

    </div>
    <!-- Row end -->

</div>
</div>
</div>

<script>
    var ot='{{.ot}}'
    $("#next-button-s").click(function(){
        var _id=""
        $("#chage-goods-list a").each(function(){
            _id=_id+","+$(this).find("span").attr("data-id");
        })
        console.log(_id)
        _id=_id.slice(1,_id.length)
        $.get("/goods/ajaxsession",{ot:ot,id:_id},function(){
            window.location.href="/"+ot+"/add"
        })
    })

    $("tbody").on("click",".am-btn",function(){
        var _id=$(this).attr("data-id")
        var _name=$(this).attr("data-name")
        var sh=0
        $("#chage-goods-list a").each(function(){
            if($(this).find("span").attr("data-id")==_id){
                sh=1;
            }
        })
        if (sh==0){
            var _html='<a class="am-btn am-btn-default" style="margin-left:5px"> '+ _name +' <span class="am-icon-trash-o" data-id="'+_id+'"></span></a>'
            $("#chage-goods-list").append(_html)
        }
    })

    $("#chage-goods-list").on("click","a span",function(){
        $(this).parent().remove()
    })
    $("#sereach-w").click(function(){
        var _w=$("#wards").val()
        $.post("/goods/ajaxlist",{w:_w},function(data){
            if(data.List.length>0){
                var s=CreatHtml(data.List)
                $("tbody").html(s)
                $("#page-list").html(data.page)

            }else{
                alert("没有更多数据了")
            }
        },"json")
    })
    function CreatHtml(data){
        var _html=""
        data.forEach(function(val) {
            _html=_html+'<tr>'+
                            '<td><a class="am-btn am-btn-default" data-id="'+val["Id"]+'" data-name='+val["Name"]+'>选择</a></td>'+
                            '<td>'+val["Id"]+'</td>'+
                            '<td>'+val["Gcode"]+'</td>'+
                            '<td>'+val["Name"]+'</td>'+
                            '<td>'+val["Units"]+'</td>'+
                            '<td>'+val["Price"]+'</td>'+
                            '<td>'+val["Spec"]+'</td>'+
                            '<td>'+val["Gmodel"]+'</td>'+
                            '<td>'+val["Sname"]+'</td>'+
                            '<td>'+val["Status"]+'</td>'+
                            '<td>'+val["SaleStatus"]+'</td>';
        }, this);
        return _html
    }
</script>